package com.kaka.bus.engine.home.main.limit;

import com.kaka.bus.bean.BpmList;
import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.bean.ProductDetailBean;
import com.kaka.bus.bean.Status;
import com.kaka.bus.constant.Constant;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.engine.common.impl.LoanService;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by OnionMac on 2018/7/30.
 */

public class LimitPresenter extends RxPresenter<LimitContract.View> implements LimitContract.Presenter {

    private LoanService mLoanService;

    @Inject
    public LimitPresenter(DataManager dataManager, LoanService loanService) {
        super(dataManager);
        mLoanService = loanService;
        setService(mLoanService);
    }

    @Override
    public void bpmList(String userId, String token, String productId) {
        mView.showDialog(Constant.LOAD);
        mLoanService.getBpmList(userId, token, productId, new Result<HttpWrapper<List<BpmList>>>() {
            @Override
            protected void onSuccess(HttpWrapper<List<BpmList>> wrapper) {
                mView.bpmListSuccess(wrapper);
            }

            @Override
            protected void onFinish() {
                super.onFinish();
                mView.dissDialog();
            }
        });
    }

    @Override
    public void checkBpm(String userId, String token) {
        mLoanService.checkBpm(userId, token, new Result<HttpWrapper<Status>>() {
            @Override
            protected void onSuccess(HttpWrapper<Status> wrapper) {
                mView.checkBpmSuccess(wrapper);
            }
        });
    }

    @Override
    public void recommend(String userId, String token, String device, String version) {
        addSubscribe(mDataManager.getApi().getRecommend(userId, token, device, version)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<ProductDetailBean>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<ProductDetailBean> listHttpWrapper) {
                        mView.recommendSuccess(listHttpWrapper);
                    }
                }));
    }
}
